<?php
/**
 * 调用 API Service 提供的接口服务
 */
class DemoAPIClient {

    /**
     * 调用 demo api 
     * @param type $method
     * @param type $args
     * @return type
     * @throws API_Exception
     */
    public static function call($method, $args) {

        $conf = V::config('demo_api_service');
        $client = new API_Client($conf['name'], $conf['key']);
        $client->setUrl($conf['url']);
        if (!empty($conf['host'])) {
            $client->setHost($conf['host']);
        }
        try {
            $res = $client->callMethod($method, $args);
        } catch (Exception $ex) {
            throw new API_Exception('call demo api service failed: '.$ex->getMessage(), API_Exception::E_LOGIC_ERROR);
        }
        if (!$res || $res['code'] !== 0) {
            throw new API_Exception($res['message'], $res['code']);
        }

        return $res['result'];
    }
}
